package by.dvrudenko.avtobaza.webapp.page.createResponses;

import java.util.List;

import javax.inject.Inject;

import org.apache.wicket.bean.validation.PropertyValidator;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;




import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import by.dvrudenko.avtobaza.datamodel.Responses;
import by.dvrudenko.avtobaza.datamodel.City;
import by.dvrudenko.avtobaza.datamodel.User;
import by.dvrudenko.avtobaza.services.ResponsesService;
import by.dvrudenko.avtobaza.services.UserService;
import by.dvrudenko.avtobaza.webapp.app.BasicAuthenticationSession;
import by.dvrudenko.avtobaza.webapp.page.BaseLayout;
import by.dvrudenko.avtobaza.webapp.page.car.panel.CarListPanel;
import by.dvrudenko.avtobaza.webapp.page.home.HomePage;
import by.dvrudenko.avtobaza.webapp.utils.renderer.UserChoiseRenderer;

public class CreateResponsesPage extends BaseLayout {

	@Inject
	private ResponsesService responsesService;
	
	@Inject
	private UserService userService;
	
	private static final Logger LOGGER = LoggerFactory.getLogger(CreateResponsesPage.class);
	
	private final ChallengeModel challengeModel = new ChallengeModel();
		
	public CreateResponsesPage(final Responses response) {
		super();

		Form<Responses> formCreateResponse = new Form<Responses>("form", new CompoundPropertyModel<Responses>(response));

		formCreateResponse.add(new SubmitLink("sumbit-link") {
			@Override
			public void onSubmit() {
				super.onSubmit();
				response.setUser(user);
				responsesService.saveOrUpdate(response);
				LOGGER.info(user.getId() + "- userId create responses");
					setResponsePage(HomePage.class);
			}
		});
		
		add(formCreateResponse);
		
		final TextArea<String> responsesText = new TextArea<String>("responsesText");
		responsesText.add(new PropertyValidator<String>());
		formCreateResponse.add(responsesText);
		
		
		formCreateResponse.add(new Captcha("captcha"));
		

	}



}
